# Mostly written by Jonathan Larmour, Red Hat, Inc.
# Reference to ecos.mak added by John Dallaway, eCosCentric Limited, 2003-01-20
# This file is in the public domain and may be used for any purpose

# Usage:   make INSTALL_DIR=/path/to/ecos/install

INSTALL_DIR=/home/ivan/ecos/synth-kernel_install

APP=craneSystem

ECOS_GLOBAL_CFLAGS = -Wall -Wpointer-arith -Wstrict-prototypes -Winline -Wundef -Woverloaded-virtual -O3 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fvtable-gc -finit-priority
ECOS_GLOBAL_LDFLAGS = -g -nostdlib -Wl,--gc-sections -Wl,-static
ECOS_COMMAND_PREFIX = i386-elf-

XCC           = $(ECOS_COMMAND_PREFIX)gcc
XCXX          = $(XCC)
XLD           = $(XCC)

CFLAGS        = -I$(INSTALL_DIR)/include
CXXFLAGS      = $(CFLAGS)
LDFLAGS       = -nostartfiles -L$(INSTALL_DIR)/lib -Ttarget.ld

OBJ = craneSystem.o crane.o powerUp.o posSensors.o CheckAlfa.o \
        CheckMinMaxPos.o CheckPosdesired.o Merger.o BrakeCondition.o \
        ControlAlg.o ControlBrake.o IsKnown.o

# RULES

.PHONY: all clean

all: $(APP)
       
clean:
	-rm -f *.o *.bin $(APP)

%.o: %.c
	$(XCC) -c -o $*.o $(CFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.cxx
	$(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.C
	$(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.cc
	$(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

$(APP): $(OBJ)
	$(XLD) $(LDFLAGS) $(ECOS_GLOBAL_LDFLAGS) -o $@ $(OBJ)
	$(ECOS_COMMAND_PREFIX)objcopy -I elf32-i386 -O binary $@ $@.bin
#	@rm $@
